package com.remoter.transport.socket.server.task;

import com.remoter.basic.bean.support.RemoterRequest;
import com.remoter.basic.bean.support.RemoterResponse;
import com.remoter.basic.task.support.AbstractMessageTaskCallBack;

import io.netty.channel.ChannelHandlerContext;

/**
 * @author			koko
 * @date 			2017-08-09 09:26:55
 * @description 	类功能说明
 */
public class SocketMessageTaskCallBack extends AbstractMessageTaskCallBack{

	private final RemoterResponse remoterResponse;
	private final ChannelHandlerContext channelHandlerContext;
	
	public SocketMessageTaskCallBack(RemoterRequest remoterRequest,RemoterResponse remoterResponse,ChannelHandlerContext ctx){
		this.remoterResponse = remoterResponse;
		this.channelHandlerContext = ctx;
	}
	
	@Override
	public void onFailure(Throwable throwable) {
		this.remoterResponse.setException(throwable.getMessage());
		this.channelHandlerContext.writeAndFlush(this.remoterResponse);
	}
	
	@Override
	public void onSuccess(Boolean value) {
		this.channelHandlerContext.writeAndFlush(this.remoterResponse);
	}
	
}